package com.um.jdy.app.activity.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.activity.entity.dto.*;
import com.um.jdy.app.activity.entity.vo.*;
import com.um.jdy.app.activity.manager.CouponsManager;
import com.um.jdy.app.shop.entity.vo.GoodsItemVO;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 活动
 * @author renjunwei
 * @date 2020/11/11 09:40
 */
@SaCheckLogin
@Validated
@Api(tags = "优惠券")
@RestController
@RequestMapping("/api/v1/coupons/")
public class CouponsController {

    @Autowired
    CouponsManager couponsManager;



    /**
     * 领取优惠券
     * @param id
     * @return
     */
    @ApiOperation("领取优惠券")
    @PostMapping("receive/{id}")
    public Response receive(@ApiParam("优惠券ID") @PathVariable String id){
        couponsManager.receive(id);
        return Response.success();
    }

    /**
     * 兑换优惠券
     * @param code
     * @return
     */
    @ApiOperation("兑换优惠券")
    @PostMapping("exchange/{code}")
    public Response exchange(@ApiParam("优惠券兑换码") @PathVariable String code){
        couponsManager.exchange(code);
        return Response.success();
    }


}
